from reward_component import RewardComponent

class ComplianceRiskComponent(RewardComponent):
    """合规风险奖励组件"""
    def __init__(self, weight=1.0, risk_rules=None):
        super().__init__(weight)
        self.risk_rules = risk_rules or {}
        
    def calculate(self, current_activity, next_activity, case_events, context=None):
        # 检查是否违反特定的合规规则
        risk_level = 0
        
        # 例如：特定活动顺序的风险检查
        if self.risk_rules.get('require_approval', False):
            if next_activity == '付款执行' and '主管审批' not in [e['activity'] for e in case_events]:
                risk_level += 1
                
        # 例如：特定客户类型的风险检查
        if context and 'customer_type' in context:
            if context['customer_type'] == 'high_risk' and next_activity in ['自动审批通过']:
                risk_level += 2
                
        # 风险越高，奖励越低
        return -1.0 * risk_level
    
    def get_description(self):
        return "基于合规风险的惩罚"